<template>
  <div class="header">
    <div class="header-left">
      <span class="iconfont back-icon">&#xe685;</span>
    </div>
    <div class="header-input">
      <span class="iconfont">&#xe67d;</span>
      输入城市/景点/游玩主题
    </div>
    <router-link to="/city">
      <div class="header-right">
        <!-- 1.直接使用state下的数据 -->
        <!-- {{ this.$store.state.city }} -->
        <!-- 2.使用mapState简洁代码 -->
        {{ this.city }}
        <!-- 3.使用Getters 类似computed的作用, 根据state中的数据计算出新的数据，避免数据冗余 -->
        <!-- {{ this.doubleCity }} -->
        <span class="iconfont arrow-icon">&#xe688;</span>
      </div>
    </router-link>
  </div>
</template>

<script>
import { mapState, mapGetters } from 'vuex'
export default {
  name: 'HomeHeader',
  computed: {
    // 传数组 将公用数据city 映射到 计算属性city
    ...mapState(['city']),
    // 或者传对象
    // ...mapState({
    //   city: 'city'
    // }),
    ...mapGetters({
      doubleCity: 'doubleCity'
    })
  }
}
</script>

<style lang="stylus" scoped>
// 1rem = font-size 50px
@import '~styles/varibles.styl'; // ~@等同于src目录，注意这里要加上~符号
@import '~styles/mixins.styl';

.header {
  display: flex;
  height: $headerHeight;
  line-height: $headerHeight;
  background-color: $bgColor;
  color: #fff;

  .header-left {
    width: 0.64rem;
    float: left;
    text-align: center;

    .back-icon {
      font-size: 0.4rem;
    }
  }

  .header-input {
    flex: 1;
    height: 0.64rem;
    line-height: 0.64rem;
    margin-top: 0.12rem;
    margin-left: 0.2rem;
    padding-left: 0.2rem;
    background-color: #fff;
    border-radius: 0.1rem;
    color: #ccc;
    ellipsis();
  }

  .header-right {
    min-width: 1.04rem;
    padding: 0 0.1rem;
    float: right;
    text-align: center;
    color: #fff;

    .arrow-icon {
      font-size: 0.24rem;
      margin-left: -0.04rem;
    }
  }
}
</style>
